public class InsertionSort {
    public static void main(String[] args) {

        int[] arr={3,44,38,5,47,15,36,26,27,2,46,4,19,50,48};

        //找到无序的哪一组数组是从哪个索引开始的
        int startIndex=-1;
        for (int i = 0; i < arr.length; i++) {
            if(arr[i]>arr[i+1]){
                startIndex=i+1;
                break;
            }
        }

        for (int i = startIndex; i < arr.length; i++) {
            int j=i;

            while (j>0&&arr[j]<arr[j-1]){
                int t=arr[j];
                arr[j]=arr[j-1];
                arr[j-1]=t;
                j--;
            }
        }

        printArr(arr);
    }

    private static void printArr(int[] arr){
        for (int i = 0; i < arr.length; i++) {
            System.out.println(arr[i]+" ");
        }
        System.out.println();//换行
    }
}
